/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package treegen;

import events.SpinnerValueChangedEvent;
import events.SpinnerValueChangedListener;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.PerspectiveCameraBuilder;
import javafx.scene.Scene;
import javafx.scene.SceneBuilder;
import javafx.scene.control.Button;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TitledPane;
import javafx.scene.image.Image;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import javafx.stage.Stage;

/**
 *
 * @author Елена
 */
public class TreeGen extends Application implements SpinnerValueChangedListener {
    private Scene scene;    
    private Stage _stage;
    BorderPane root;
    TabPane tabs;
    Tab trunk;
    Tab leaves;
    Tab crown;
    Tab branch;
    BranchPane branchPane;
    LeafPanel leafPanel;
    CrownPanel crownPanel;
    TrunkPanel trunkPanel;
    Tree tree;
    @Override
    public void start(Stage stage) {
        tree = new Tree(this);
        stage.setTitle("TreeGenerator");
        root = new BorderPane();
        stage.getIcons().add(new Image(TreeGen.class.getResourceAsStream("pictures/icon.png"))); 
        scene = makeScene();
        _stage = stage;
        _stage.setScene(scene);
        _stage.setResizable(false);
        // Создаем виджет со вкладками
        tabs = new TabPane();
        trunk = new Tab();
        trunk.setText("Ствол");
        trunk.setContent(new Rectangle(400,400, Color.LIGHTSTEELBLUE));
        trunk.setClosable(false);
        branch = new Tab();
        branch.setText("Ветви");
        branch.setClosable(false);
        branchPane = new BranchPane(tree);
        branch.setContent(branchPane.tabCont);
        leaves = new Tab();
        leaves.setText("Листья");
        leaves.setClosable(false);
        leafPanel = new LeafPanel();
        leaves.setContent(leafPanel.mainPane);
        crown = new Tab();
        crown.setText("Крона");
        crown.setClosable(false);
        crownPanel = new CrownPanel();
        crown.setContent(crownPanel.mainPane);
        trunkPanel = new TrunkPanel();
        trunk.setContent(trunkPanel.mainPane);
        tabs.getTabs().addAll(trunk, branch, leaves, crown);
        root.setLeft(tabs);
        //root.prefHeightProperty().bind(scene.heightProperty());
        //root.prefWidthProperty().bind(scene.widthProperty());
        _stage.show();
    }

    public void getValues() {
        int tabNum = tabs.getSelectionModel().getSelectedIndex();
        switch (tabNum) {
            case 0:
                break;
            case 1:
                TitledPane pane = branchPane.accordion.getExpandedPane();
                int index = branchPane.accordion.getPanes().indexOf(pane);
                BranchLevel cur = branchPane.branchLevels.get(index);
                cur.getValues();
                break;
            case 2:
                break;
            case 3:
                break;
        }
    }
    
    private Scene makeScene() {
        return SceneBuilder.create()
            .width(950)
            .height(650)
            .root(root)
            .camera(PerspectiveCameraBuilder.create()
                .build())
            .depthBuffer(true)
            .build();
    }
    /**
     * The main() method is ignored in correctly deployed JavaFX application.
     * main() serves only as fallback in case the application can not be
     * launched through deployment artifacts, e.g., in IDEs with limited FX
     * support. NetBeans ignores main().
     *
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void saveValue(SpinnerValueChangedEvent e) {
        getValues();
    }
    
}
